import { tenantHttp } from '/@/utils/http/axios';

interface Certificate {
  type?: string;
  name?: string;
  content?: string;
  secretKey?: string;
  modifyEnabled: boolean;
}

interface DomainInfo {
  name: string;
  icpRecordNum: string;
  certificateConfStatus: string;
  modifyEnabled: boolean;
  certificate: Certificate;
}

interface Verify {
  password: string;
  code: string;
  codeType: string;
}

interface UpdateDomainParams {
  name: string;
  icpRecordNum: string;
  certificate: Certificate;
  verify: Verify;
  tenantCode: string;
}

export const getTenantDomainConfig = (tenantCode: string) => {
  // 获取租户的域名配置
  return tenantHttp.get<DomainInfo>({
    url: `/tenants/${tenantCode}/domain`,
  });
};
export const getCertificateType = () => {
  // 获取租户的证书配置
  return tenantHttp.get({
    url: '/enums/certificate/type',
  });
};
export const getTenantCommonConfig = (tenantCode: string) => {
  // 获取租户的通用配置
  return tenantHttp.get<{
    displayName: string;
    displayLogo: string;
  }>({
    url: `/tenants/${tenantCode}/sign`,
  });
};
export const updateTenantCommonConfig = (params: { displayName: string; tenantCode: string }) => {
  // 更新租户的通用配置
  const { displayName, tenantCode } = params;
  return tenantHttp.put({
    url: `/tenants/${tenantCode}/sign`,
    data: {
      displayName,
    },
  });
};

export const updateTenantDomainConfig = (data: UpdateDomainParams) => {
  // 更新租户域名配置
  return tenantHttp.put({
    url: `/tenants/${data.tenantCode}/domain`,
    data,
  });
};
export const updateTenantCerificateConfig = (data: UpdateDomainParams) => {
  // 更新租户证书配置
  return tenantHttp.put({
    url: `/tenants/${data.tenantCode}/certificate`,
    data,
  });
};
export const updateTenantLogo = (params: { logo: File; tenantCode: string }) => {
  // 更新租户LOGO
  const { logo, tenantCode } = params;
  return tenantHttp.uploadFile(
    {
      url: `/api/admin/saaslandingTenant/tenants/${tenantCode}/logo`,
    },
    {
      file: logo,
      data: {
        tenantCode,
      },
    }
  );
};
